package com.yanxi.mapper;

import com.yanxi.pojo.Emp;
import com.yanxi.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /*    */

    /**
     * 查询总记录数
     *
     * @return
     *//*
    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
    public long count();


    @Select("select emp.*,dept.name deptName from emp  left join dept  on emp.dept_id = dept.id order by emp.update_time limit #{start},#{pageSize}")
    public List<Emp> list(Integer start,  Integer pageSize);*/
    //@Select("select emp.*,dept.name deptName from emp  left join dept  on emp.dept_id = dept.id  order by emp.update_time")
    public List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")

    //插入数据
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
            "value(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void save(Emp emp);


    //批量删除
    void deleteByIds(List<Integer> ids);

    //根据id查询员工信息
   // @Select("select emp.*,dept.name deptName from emp  left join dept  on emp.dept_id = dept.id where emp.id = #{id}")
    Emp get(Integer id);

    //更新员工信息
/*    @Insert("update emp " +
            "set username = #{username},password = #{password}, name = #{name},gender = #{gender},phone = #{phone},job = #{job},salary = #{salary},image = #{image},entry_date = #{entryDate},dept_id = #{deptId},update_time = #{updateTime} " +
            "where id = #{id}")*/
    void update(Emp emp);

    public List<Map<String,  Object>> CountEmpJobData();

    List<Map<String, Object>> CountEmpGenderData();


    //查询所有员工信息
    @Select("select * from emp ")
    List<Emp> listAll();


    @Select("select id, username, name from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}